package com.yfht.common.utils;

import java.util.Enumeration;
import java.util.Properties;
import java.util.ResourceBundle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
 * system范围的属性，配置需要加载如系统的配置文件，在以后的其他位置可以用到这些配置项
 * @author yuan
 *
 */
public class PropertiesUtils {
	private static final Log logger = LogFactory.getLog(PropertiesUtils.class);
	/**
	 * 属性文件配置
	 */
	private static Properties props = new Properties();
	public static String classPath;
	public static String projectPath;

	public static Properties getProps(){
		return PropertiesUtils.props;
	}
	
	public static void setProperty(String key, String value){
		props.setProperty(key, value);
	}
	/**
	 * FunName: loadBundle
	 * <p>
	 * Description : 根据配置路径读取配置信息
	 * 
	 * @param key
	 * 配置信息的定义
	 * @return String 配置信息的取值
	 */
	public static void loadBundle(String bundlePath){
		ResourceBundle appProps = ResourceBundle.getBundle(bundlePath);
		Enumeration enums = appProps.getKeys();
		while (enums.hasMoreElements()) {
			String key = enums.nextElement().toString();
			props.put(key, appProps.getString(key));
		}
	}
	/**
	 * FunName: getProperty
	 * <p>
	 * Description : 取得配置信息
	 * 
	 * @param key
	 * 配置信息的定义
	 * @return String 配置信息的取值
	 */
	public static String getProperty(String key) {
		String value = "";
		try {
			value = props.getProperty(key);
		} catch (Exception e) {
			e.printStackTrace();
			if (logger.isErrorEnabled())
				logger.error("读取配置" + key + "出错!");
		}
		return value;
	}

	public static Integer getPropertyInteger(String key) {
		Integer value = null;
		try {
			String tempStr = props.getProperty(key);
			if (tempStr != null) {
				return Integer.getInteger(tempStr);
			}
		} catch (Exception e) {
			e.printStackTrace();
			if (logger.isErrorEnabled())
				logger.error("读取配置" + key + "出错!");
		}
		return value;
	}
}
